package dao;

import entity.UserInfo;
import openConn.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserInfoDao {
    public static UserInfo login(String userName,String passWord) throws SQLException {
        Connection connection = DruidUtils.openConn();
        String sql = "select * from user_info where user_name = ? and password = ?";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1,userName);
        statement.setString(2,passWord);
        ResultSet resultSet = statement.executeQuery();
        UserInfo userInfo = null;
        while (resultSet.next()){
            String userName1 = resultSet.getString("user_name");
            String passWord1 = resultSet.getString("password");
            userInfo = new UserInfo(userName1,passWord1);
        }
        resultSet.close();
        statement.close();
        connection.close();
        return userInfo;
    }
}
